package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Personinfo;
import com.ruoyi.system.service.IPersoninfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公民基础信息Controller
 * 
 * @author TYF
 * @date 2023-08-12
 */
@Controller
@RequestMapping("/system/personinfo")
public class PersoninfoController extends BaseController
{
    private String prefix = "system/personinfo";

    @Autowired
    private IPersoninfoService personinfoService;

    @RequiresPermissions("system:personinfo:view")
    @GetMapping()
    public String personinfo()
    {
        return prefix + "/personinfo";
    }

    /**
     * 查询公民基础信息列表
     */
    @RequiresPermissions("system:personinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Personinfo personinfo)
    {
        startPage();
        List<Personinfo> list = personinfoService.selectPersoninfoList(personinfo);
        return getDataTable(list);
    }

    /**
     * 导出公民基础信息列表
     */
    @RequiresPermissions("system:personinfo:export")
    @Log(title = "公民基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Personinfo personinfo)
    {
        List<Personinfo> list = personinfoService.selectPersoninfoList(personinfo);
        ExcelUtil<Personinfo> util = new ExcelUtil<Personinfo>(Personinfo.class);
        return util.exportExcel(list, "公民基础信息数据");
    }

    /**
     * 新增公民基础信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公民基础信息
     */
    @RequiresPermissions("system:personinfo:add")
    @Log(title = "公民基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Personinfo personinfo)
    {
        return toAjax(personinfoService.insertPersoninfo(personinfo));
    }

    /**
     * 修改公民基础信息
     */
    @RequiresPermissions("system:personinfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Personinfo personinfo = personinfoService.selectPersoninfoById(id);
        mmap.put("personinfo", personinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存公民基础信息
     */
    @RequiresPermissions("system:personinfo:edit")
    @Log(title = "公民基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Personinfo personinfo)
    {
        return toAjax(personinfoService.updatePersoninfo(personinfo));
    }

    /**
     * 删除公民基础信息
     */
    @RequiresPermissions("system:personinfo:remove")
    @Log(title = "公民基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(personinfoService.deletePersoninfoByIds(ids));
    }


    /**
     * 导入公民基础信息
     */
    @PostMapping( "/uploadInfo")
    @ResponseBody
    public AjaxResult uploadInfo()
    {
        return toAjax(personinfoService.uploadInfo());
    }


    /**
     * 导入公民电话和地址
     */
    @PostMapping( "/uploadInfoTelOrAddress")
    @ResponseBody
    public AjaxResult uploadInfoTelOrAddress()
    {
        return toAjax(personinfoService.uploadInfoTelOrAddress());
    }



    /**
     * 导入公民案例
     */
    @PostMapping( "/uploadInfoCase")
    @ResponseBody
    public AjaxResult uploadInfoCase()
    {
        return toAjax(personinfoService.uploadInfoCase());
    }
}
